package com.one.shopping.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.one.shopping.R;
import com.one.shopping.entity.ShoppingCart;

import java.util.List;

/**
 * Created by Administrator on 2016/1/13.
 */
public class OrdersGoodsAdapter extends BaseAdapter{

    private Context context;
    private List<ShoppingCart> list;

    public OrdersGoodsAdapter(Context context, List<ShoppingCart> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        // TODO 自动生成的方法存根
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO 自动生成的方法存根
        return list.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO 自动生成的方法存根
        return arg0;
    }

    @Override
    public View getView(int arg0, View converView, ViewGroup arg2) {
//		//1.找到布局
//		LayoutInflater inflater=LayoutInflater.from(context);
//		converView=inflater.inflate(R.layout.item,null);
//
//
//		//2.找到组件
//		MyView view=new MyView();
//		view.iv=(ImageView) converView.findViewById(R.id.item_iv);
//		view.tV=(TextView) converView.findViewById(R.id.item_tv);
//
//
//		//3.给对应的组件赋值
//
//		view.iv.setImageResource(R.drawable.c);
//		view.tV.setText(list.get(arg0).getName());
//

        MyGoodsView view;
        if(converView==null){
            //没有找过布局没有找过组件
            LayoutInflater inflater=LayoutInflater.from(context);
            converView=inflater.inflate(R.layout.goodslist,null);
            view=new MyGoodsView();
            view.goodsNameTv = (TextView)converView.findViewById(R.id.goodsNameTv);
            view.quantityTv = (TextView)converView.findViewById(R.id.quantityTv);
            view.univalentTv = (TextView)converView.findViewById(R.id.univalentTv);
            view.moneyTv = (TextView)converView.findViewById(R.id.moneyTv);
            converView.setTag(view);
        }else{
            view=(MyGoodsView) converView.getTag();
        }
        view.goodsNameTv.setText(list.get(arg0).getName());
        view.quantityTv.setText(list.get(arg0).getQuantity()+"");
        view.univalentTv.setText(list.get(arg0).getPrice()+"");

        view.moneyTv.setText(""+Double.parseDouble(list.get(arg0).getPrice()) * list.get(arg0).getQuantity());
        return converView;
    }

}


class MyGoodsView{
    public TextView goodsNameTv;
    public TextView quantityTv;
    public TextView univalentTv;
    public TextView moneyTv;
}
